<?php

error_reporting(0);
require_once("../in/tren.php");
header("content-type:text/html; charset=UTF-8");
@session_start();
require_once("../in/tren.php");
require_once("../in/zip.php");
$tit = 'Game Mobile';
echo'<div class="navigation"><b>Game Mobile</b></div><div align="right"><div style="border-top: 3px solid #13cfeb;"></div></div></div><div class="main_menu">';
$sql = @mysql_query("SELECT * FROM game WHERE id='" . $_GET['id'] . "'");
if ($set['taive'] != op && !$user_id) {
    echo '<span style="color:blue">Hãy <a href="' . $set['home'] . '/log.php">Đăng Nhập</a> hoặc <a href="' . $set['home'] . '/reg.php">Đăng Kí</a> để tải game.';
} else {
    if (mysql_num_rows($sql) == 0) {
        echo '<img src="../img/loi.png"> Đường dẫn đến ID không hợp lệ hoặc nó đã bị xóa!</div>';
    } else {
        $file = mysql_fetch_assoc($sql);
        mysql_query("UPDATE `game` SET `down` = `down`+'1' where id = '" . $_GET['id'] . "'");
        $link = '' . $set['home'] . '/fgame/' . $file['link'] . '';
        $get_file = file_get_contents($link);
        $tmp = fopen('../jad/jad.jar', 'w+');
        fputs($tmp, $get_file);
        fclose($tmp);
        chmod('../jad/jad.jar', 0644);
        $name = strtok(basename($link), '.');
        $size = filesize('../jad/jad.jar');
        $archive = new PclZip('../jad/jad.jar');
        $list = $archive->extract(PCLZIP_OPT_BY_NAME, 'META-INF/MANIFEST.MF', PCLZIP_OPT_EXTRACT_AS_STRING);
        $jad = $list[0]['content'];
        $f = fopen('../jad/files/' . $name . '.jad', 'w+');
        fputs($f, $jad . '
MIDlet-Jar-Size: ' . $size . '
MIDlet-Jar-URL: ' . $link);
        fclose($f);
        header('Location:' . $set['home'] . '/jad/files/' . $name . '.jad');
    }
}
require_once("../in/duoi.php");
?>
